<?php 
   $sprodName = $this->ts_functions->getProductName($productdetails[0]['prod_id']);
   $sprodImage = $this->ts_functions->getProductPic($productdetails[0]['prod_image']);
   $sprodUrl   = base_url().'item/'. $sprodName.$productdetails[0]['prod_uniqid'];
   
   $scatename = strtolower($productdetails[0]['cate_urlname']);
   $scatename = str_replace(' ','-',$scatename);
   $scatename = preg_replace('!-+!', '-', $scatename);
   $scat_url  =base_url().'home/products/'. $scatename;
   $sprod_demourl='';
   if($productdetails[0]['prod_demourl']){
	$sprod_demourl= base_url().'item/'.$sprodName.'live_demo/'.$productdetails[0]['prod_uniqid']; 
   }
   
   if( $productdetails[0]['prod_free'] == '0') {
	  $sprod_price=$this->ts_functions->getsettings('portalcurreny','symbol').' '.$productdetails[0]['prod_price']; 
   }else{
	  $sprod_price=$this->ts_functions->getlanguage('freetext','commontext','solo'); 
   }
   if( $this->ts_functions->getsettings('portal','revenuemodel') != 'subscription' ) {
	   $spurDetail = $this->DatabaseModel->access_database('ts_purchaserecord','select','',array('purrec_prodid'=>$productdetails[0]['prod_id']));
	   $sprod_sale=count($spurDetail);
   }else{
	  $sprod_sale=$productdetails[0]['prod_download_count']; 
   }
   $svendorName = $this->ts_functions->getVendorName($productdetails[0]['prod_uid']);
   $svendor_url=base_url().'vendor/'.$svendorName;
   $sprod_title=$productdetails[0]['prod_name'];
   
   $prod_gallery = $this->DatabaseModel->access_database('ts_prodgallery','select', '' , array('prodgallery_pid'=>$productdetails[0]['prod_id']) );

?>

<div class="tp_page_title">
	<div class="container">
		<div class="row">
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
				<div class="tp_page_heading">
					<h3><?php echo $sprod_title;?></h3>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="tp_gray_wrapper tp_toppadder80 tp_bottompadder80">
	<div class="container">
		<div class="row">
			<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
				<div class="tp_product_div">
					<div class="tp_product_img tp_product_singleitem">
						<img src="<?php echo $sprodImage; ?>" class="img-responsive" alt="<?php echo $sprod_title;?>">
					</div>
					<div class="tp_product_data">
					    <input type="hidden" id="prod_id" value="<?php echo $productdetails[0]['prod_id']; ?>">
						<h3><?php echo $sprod_title;?></h3>
						
						<ul>
							<li><a href="<?php echo $svendor_url;  ?>"><i class="fa fa-user"></i> <?php echo ucfirst($svendorName); ?></a></li>
							<li><a href="<?php echo $scat_url; ?>"><i class="fa fa-tag"></i><?php echo $scatename; ?></a></li>
						</ul>
						<div class="tp_divider"></div>
						<div class="tp_sales_data">
							<h4><i class="fa fa-shopping-cart"></i> <?php echo $sprod_sale.' ' . $this->ts_functions->getlanguage('salestext','commontext','solo'); ?> </h4>
						</div>
						<div class="tp_price_div">
							<h4><?php echo $sprod_price; ?></h4>
						</div>
						
						<div class="tp_btndiv tp_btn_left">
						
							
							<?php
							 if($sprod_demourl!=''){?>
							  <a href="<?php echo $sprod_demourl; ?>" class="tp_btn"><?php echo $this->ts_functions->getlanguage('livedemotab','homepage','solo');?></a>
							 <?php }?>
							
							
							<?php
                             if(!empty($prod_gallery)){
							   if($productdetails[0]['prod_type'] == 'Audio') {
								 $btn_kw = 'listenbtn'; $prod_type = 'audio';
								}elseif( $productdetails[0]['prod_type'] == 'Video' ){
									$btn_kw = 'videobtn'; $prod_type = 'video';
								}elseif( $productdetails[0]['prod_type'] == 'Text' ){
									$btn_kw = 'viewbtn'; $prod_type = 'text';
								}else {
									$btn_kw = 'gallerybtn'; $prod_type = 'other';
								}
								
								if( $productdetails[0]['prod_type'] == 'Text' ) { 
								  $down_link = base_url().'home/download_preview_text/'.$productdetails[0]['prod_id'];
								  ?>
								  <a onclick="window.location = '<?php echo $down_link; ?>'" class="tp_btn pull-left popup_open_preview"><?php echo $this->ts_functions->getlanguage($btn_kw,'homepage','solo');?></a>
								 <?php } else if( $productdetails[0]['prod_type'] == 'Other' ) { ?>
								 <a onclick="$('.popup-gallery').find('img:first').trigger('click');" class="tp_btn pull-left popup_open_preview"><?php echo $this->ts_functions->getlanguage($btn_kw,'homepage','solo');?></a>
								 <?php }else { ?>
							
							     <a onclick="openthegalleryimages(<?php echo $productdetails[0]['prod_id'];?>,'<?php echo $prod_type;?>');" class="tp_btn pull-left popup_open_preview"><?php echo $this->ts_functions->getlanguage($btn_kw,'homepage','solo');?></a>
						
						         <?php } ?>
								
                             								
							 <?php }?>
						</div>
						<div>
						<?php echo $productdetails[0]['prod_description'];?>
						</div>
					</div>
				</div>
				<?php if(!empty($relatedProducts)) { ?>
				<div class="tp_related_product">
					<h2><?php echo $this->ts_functions->getlanguage('relatedprodtext','commontext','solo'); ?></h2>
					<div class="tp_related_product_slider">
					  <div class="owl-carousel owl-theme">
						 <?php foreach($relatedProducts as $soloFet){
							 $prodName = $this->ts_functions->getProductName($soloFet['prod_id']);
						   $prodImage = $this->ts_functions->getProductPic($soloFet['prod_image']);
						   $prodUrl   = base_url().'item/'. $prodName.$soloFet['prod_uniqid'];
						   
						   $catename = strtolower($soloFet['cate_urlname']);
						   $catename = str_replace(' ','-',$catename);
						   $catename = preg_replace('!-+!', '-', $catename);
						   $cat_url  =base_url().'home/products/'. $catename;
						   $prod_demourl='';
						   if($soloFet['prod_demourl']){
							$prod_demourl= base_url().'item/'.$prodName.'live_demo/'.$soloFet['prod_uniqid']; 
						   }
						   
						   if( $soloFet['prod_free'] == '0') {
							  $prod_price=$this->ts_functions->getsettings('portalcurreny','symbol').' '.$soloFet['prod_price']; 
						   }else{
							  $prod_price=$this->ts_functions->getlanguage('freetext','commontext','solo'); 
						   }
						   if( $this->ts_functions->getsettings('portal','revenuemodel') != 'subscription' ) {
							   $purDetail = $this->DatabaseModel->access_database('ts_purchaserecord','select','',array('purrec_prodid'=>$soloFet['prod_id']));
							   $prod_sale=count($purDetail);
						   }else{
							  $prod_sale=$soloFet['prod_download_count']; 
						   }
						   $vendorName = $this->ts_functions->getVendorName($soloFet['prod_uid']);
						   $vendor_url=base_url().'vendor/'.$vendorName;
						   $prod_title=$soloFet['prod_name'];
						   ?>
							<div class="item">
								<div class="tp_product_div">
									<div class="tp_product_img">
										<img src="<?php echo $prodImage; ?>" class="img-responsive" alt="<?php echo $prod_title; ?>">
										<?php
										 if($prod_demourl!=''){?>
										  <div class="tp_overlay"></div>
											<div class="tp_overlay_btn">
												<a href="<?php echo $prod_demourl; ?>" class="tp_btn" target="_blank"><?php echo $this->ts_functions->getlanguage('livedemotab','homepage','solo');?></a>
											</div>	 
											 
										 <?php }?>
									</div>
									<div class="tp_product_data">
										<h3><a href="<?php echo $prodUrl; ?>"><?php echo $soloFet['prod_name'];  ?></a></h3>
						                <p><?php echo substr(strip_tags($soloFet['prod_description']),0,150).' ...';?></p>
										<ul>
											<li><a href="<?php echo $vendor_url;  ?>"><i class="fa fa-user"></i> <?php echo ucfirst($vendorName); ?></a></li>
											<li><a href="<?php echo $cat_url; ?>"><i class="fa fa-tag"></i><?php echo $catename; ?></a></li>
										</ul>
										<div class="tp_divider"></div>
										<div class="tp_sales_data">
											<h4><i class="fa fa-shopping-cart"></i> <?php echo $prod_sale.' ' . $this->ts_functions->getlanguage('salestext','commontext','solo'); ?> </h4>
										</div>
										<div class="tp_price_div">
											<h4><?php echo $prod_price; ?></h4>
										</div>
										<div class="tp_btndiv">
											<a href="<?php echo $prodUrl; ?>" class="tp_btn"><?php echo $this->ts_functions->getlanguage('viewbtn','homepage','solo') ?></a>
										</div>
									</div>
								</div>
							</div>
						 <?php } ?>
							
						</div>
					</div>
				</div>
				<?php } ?>
			</div>
			<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
				<div class="tp_sidebar">
					<div class="tp_sidebar_div tp_text_content">
						<h3><?php echo $this->ts_functions->getlanguage('licenseheading','singleproductpage','solo');?></h3>
						<p><?php echo $this->ts_functions->getlanguage('licensesubheading','singleproductpage','solo');?></p>
						
						<div class="tp_btndiv">
							<?php if( $productdetails[0]['prod_free'] == '0') {
                                if( $this->ts_functions->getsettings('portal','revenuemodel') != 'subscription' ) { ?>

                                    <a href="<?php echo $basepath;?>shop/add_to_cart/products/<?php echo $productdetails[0]['prod_uniqid'];?>" class="tp_btn"> <?php echo $this->ts_functions->getlanguage('addtocart','homepage','solo');?> </a>

                                    <a href="<?php echo $basepath;?>shop/add_to_cart/products/<?php echo $productdetails[0]['prod_uniqid'];?>" class="tp_btn"> <?php echo $this->ts_functions->getlanguage('buynowtab','homepage','solo');?> - <?php echo $this->ts_functions->getsettings('portalcurreny','symbol');?><?php echo $productdetails[0]['prod_price'];?> </a>

                                <?php } else { ?>
                                    <a href="<?php echo $basepath;?>shop/checkmembership/<?php echo $productdetails[0]['prod_uniqid'];?>" class="tp_btn"> <?php echo $this->ts_functions->getlanguage('buynowtab','homepage','solo');?> </a>
							<?php   }
							    } else {
							        // Free
							    ?>
							        <a href="<?php echo $basepath;?>shop/add_to_cart/products/<?php echo $productdetails[0]['prod_uniqid'];?>" class="tp_btn"> <?php echo $this->ts_functions->getlanguage('freetext','commontext','solo');?></a>

							<?php } ?>
						</div>
					</div>
					
					<div class="tp_sidebar_div">
						<h3><?php echo $this->ts_functions->getlanguage('productheading','singleproductpage','solo');?></h3>
						<div class="tp_author_detail">
							<img src="<?php echo $basepath.'webimage/'.$this->ts_functions->getVendorPic($productdetails[0]['prod_uid']);?>" alt="<?php echo $svendorName;?>" title="<?php echo $svendorName;?>">
							<h4><a href="<?php echo $svendor_url ?>"><?php echo $svendorName; ?></a></h4>
						</div>
						<div class="tp_product_info">
							<p><strong><?php echo $this->ts_functions->getlanguage('createsubheading','singleproductpage','solo');?></strong> : <?php echo date_format(date_create ( $productdetails[0]['prod_date'] ) , 'M d, Y');?></p>
							<p><strong><?php echo $this->ts_functions->getlanguage('updateddatetext','singleproductpage','solo');?></strong> : <?php echo date_format(date_create ( $productdetails[0]['prod_update'] ) , 'M d, Y');?></p>
							
							<p>
							<?php $rating_count = $rating_count[0]['tot_stars'];?>					
							<strong><?php echo $this->ts_functions->getlanguage('ratingssubheading','singleproductpage','solo');?>
							</strong>
							<span><i class="fa fa-star<?php echo ($rating_count < 1) ? '-o' : '' ; ?>"></i></span>
							<span><i class="fa fa-star<?php echo ($rating_count < 2) ? '-o' : '' ; ?>"></i></span>
							<span><i class="fa fa-star<?php echo ($rating_count < 3) ? '-o' : '' ; ?>"></i></span>
							<span><i class="fa fa-star<?php echo ($rating_count < 4) ? '-o' : '' ; ?>"></i></span>
							<span><i class="fa fa-star<?php echo ($rating_count < 5) ? '-o' : '' ; ?>"></i></span>
							</p>
							<p><strong><?php echo $this->ts_functions->getlanguage('commentstext','singleproductpage','solo');?></strong> : <?php echo $comment_count;?> <a href="<?php echo $com_url; ?>"><i class="fa fa-comment"></i></a></p>
							<p><strong><?php echo $this->ts_functions->getlanguage('downloadssubheading','singleproductpage','solo');?></strong> : <?php echo $sprod_sale; ?></p>
							
							<!-- Rate This -->
					<?php if(isset($this->session->userdata['ts_uid'])): ?>
								<?php
								$uid=$this->session->userdata['ts_uid'];
								$check_previous_rating=false;
								
								if($productdetails[0]['prod_free']==0){
									if( $this->ts_functions->getsettings('portal','revenuemodel') != 'subscription' ) {
									$checkpurchase=$this->DatabaseModel->access_database('ts_purchaserecord','select','',array('purrec_prodid'=>$productdetails[0]['prod_id'],'purrec_uid'=>$uid));
									}else{
									 $checkpurchase=$this->DatabaseModel->access_database('ts_downloadtbl','select','',array('download_pid'=>$productdetails[0]['prod_id'],'download_uid'=>$uid));	
									}
									if(empty($checkpurchase)){
									$check_previous_rating=true;	
									}else{
										$check_previous_rating=false;
									}
								}
								if($check_previous_rating==false){
								$check_past_rating=$this->DatabaseModel->access_database('ts_ratings','select','',array('rating_prodid'=>$productdetails[0]['prod_id'],'rating_uid'=>$uid));
								if(empty($check_past_rating)){
									$check_previous_rating=false;	
									}else{
										$check_previous_rating=true;
									}
								}
								?>
								<?php if($check_previous_rating==false){ ?>
							<p class="ts_rating demo-table give_rating">
												
							<strong><?php echo $this->ts_functions->getlanguage('ratethis','singleproductpage','solo');?>
							</strong>
							
							<span onmouseover="highlightStar(this);"  onClick="addRating(this);"><a class="rating_star " alt="1"><i class="fa fa-star-o"></i></a></span>
							<span onmouseover="highlightStar(this);"  onClick="addRating(this);"><a class="rating_star " alt="2"><i class="fa fa-star-o"></i></a></span>
							<span onmouseover="highlightStar(this);"  onClick="addRating(this);"><a class="rating_star " alt="3"><i class="fa fa-star-o"></i></a></span>
							<span onmouseover="highlightStar(this);"  onClick="addRating(this);"><a class="rating_star " alt="4"><i class="fa fa-star-o"></i></a></span>
							<span onmouseover="highlightStar(this);"  onClick="addRating(this);"><a class="rating_star " alt="5"><i class="fa fa-star-o"></i></a></span>
							
							
							
							</p>
							<?php } ?>								
								<?php endif; ?>
					<!-- end Rate this -->
	
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<?php

	if( $productdetails[0]['prod_type'] == 'Audio' || $productdetails[0]['prod_type'] == 'Video' ) {
	if(!empty($prod_gallery)) { ?>
	<!-- PopUp wrappe Start -->
<div class="ts_popup_wrapper">
	<div class="ts_popup_close_overlay"></div>
	<a class="ts_popup_close"><i class="fa fa-times" aria-hidden="true"></i></a>
	<div class="ts_popup_inner ts_video_popup" id="popupgallery">
        <ul>
            <li id="img_0" class="currentActive">
            <?php if( $productdetails[0]['prod_type'] == 'Audio' ) { ?>
            
            <audio controls id="tp_audio"> <source src="<?php echo base_url().'repo/gallery/p_'.$productdetails[0]['prod_id'].'/'.$prod_gallery[0]['prodgallery_img']; ?>" type="audio/mpeg">Your browser does not support the audio element.</audio>
            
            <?php } else { ?>
            
            <video controls id="tp_video"> <source src="<?php echo base_url().'repo/gallery/p_'.$productdetails[0]['prod_id'].'/'.$prod_gallery[0]['prodgallery_img']; ?>" type="video/mp4">Your browser does not support the video element.</video>  
                      
            <?php } ?>
            </li>
        </ul>
	</div>
</div>
<!-- PopUp wrappe End -->
<?php } } else { ?>
	
	
	<!-- PopUp wrappe Start -->
	<div class="popup-gallery" style="display:none;">
		
		
<?php foreach( $prod_gallery as $solo_gallery) { ?>
		<a href="<?php echo base_url().'repo/gallery/p_'.$productdetails[0]['prod_id'].'/'.$solo_gallery['prodgallery_img']; ?>">
			<img src="<?php echo base_url().'repo/gallery/p_'.$productdetails[0]['prod_id'].'/'.$solo_gallery['prodgallery_img']; ?>" width="75" height="75">
		</a>
	
<?php } ?>

	</div>
	<!-- PopUp wrappe End -->
<?php } ?>